package com.youku.plugins.controlbarV4.view
{
   import com.youku.interfaces.IPlayerProxy;
   import com.youku.plugins.PluginEventDispather;
   import com.youku.plugins.controlbarV4.view.components.ProgressBar;
   import com.youku.plugins.controlbarV4.view.events.ProgressBarEvent;
   import com.youku.plugins.controlbarV4.view.events.ControlBarEvent;
   
   public class ProgressBarMediator extends Object
   {
      
      public function ProgressBarMediator(param1:ProgressBar, param2:IPlayerProxy, param3:PluginEventDispather) {
         super();
         this._progressBar = param1;
         this._playerProxy = param2;
         this._pluginEventDispather = param3;
      }
      
      private var _playerProxy:IPlayerProxy;
      
      private var _pluginEventDispather:PluginEventDispather;
      
      private var _progressBar:ProgressBar;
      
      protected function get progressbar() : ProgressBar {
         return this._progressBar;
      }
      
      public function init() : void {
         this.progressbar.addEventListener(ProgressBarEvent.SHOW_PREVIEW_TIME,this.onProgressBarEvent);
         this.progressbar.addEventListener(ProgressBarEvent.HIDE_PREVIEW_TIME,this.onProgressBarEvent);
         this.progressbar.addEventListener(ProgressBarEvent.SHOW_PREVIEW_VIDEO,this.onProgressBarEvent);
         this.progressbar.addEventListener(ProgressBarEvent.HIDE_PREVIEW_VIDEO,this.onProgressBarEvent);
         this._pluginEventDispather.addEventListener(ControlBarEvent.SHOW_PREVIEWER_PANEL,this.onControlBarEvent);
         this._pluginEventDispather.addEventListener(ControlBarEvent.HIDE_PREVIEWER_PANEL,this.onControlBarEvent);
         this._pluginEventDispather.addEventListener(ControlBarEvent.DRAW_AD_POINTS,this.onControlBarEvent);
         this._pluginEventDispather.addEventListener(ControlBarEvent.DRAW_INTERACT_POINTS,this.onControlBarEvent);
      }
      
      private function onControlBarEvent(param1:ControlBarEvent) : void {
         switch(param1.type)
         {
            case ControlBarEvent.SHOW_PREVIEWER_PANEL:
               this.progressbar.showPreview();
               break;
            case ControlBarEvent.HIDE_PREVIEWER_PANEL:
               this.progressbar.hidePreview();
               break;
            case ControlBarEvent.DRAW_AD_POINTS:
               if(!(this._playerProxy.rootGetData.rootAdext == null) && !(this._playerProxy.rootGetData.rootAdext == ""))
               {
                  this.progressbar.addADPoints(param1.data as Array);
               }
               break;
            case ControlBarEvent.DRAW_INTERACT_POINTS:
               this.progressbar.setInteractPoint(param1.data as Array);
               break;
         }
      }
      
      private function onProgressBarEvent(param1:ProgressBarEvent) : void {
         switch(param1.type)
         {
            case ProgressBarEvent.SHOW_PREVIEW_VIDEO:
               this._pluginEventDispather.dispatchEvent(new ControlBarEvent(ControlBarEvent.SHOW_PREVIEWER,param1.data));
               break;
            case ProgressBarEvent.HIDE_PREVIEW_VIDEO:
               this._pluginEventDispather.dispatchEvent(new ControlBarEvent(ControlBarEvent.HIDE_PREVIEWER_VIDEO));
               break;
            case ProgressBarEvent.SHOW_PREVIEW_TIME:
               this._pluginEventDispather.dispatchEvent(new ControlBarEvent(ControlBarEvent.SHOW_PREVIEWER_PANEL));
               break;
            case ProgressBarEvent.HIDE_PREVIEW_TIME:
               this._pluginEventDispather.dispatchEvent(new ControlBarEvent(ControlBarEvent.HIDE_PREVIEWER_VIDEO));
               this._pluginEventDispather.dispatchEvent(new ControlBarEvent(ControlBarEvent.HIDE_PREVIEWER_PANEL));
               break;
         }
      }
   }
}
